package com.chookss.home.rank;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.chookss.R;
import com.chookss.base.BaseViewHolderEx;
import com.chookss.home.entity.NavigationEntity;
import com.chookss.tools.Utils;
import com.chookss.view.Rank2Dialog;
import com.chookss.view.RankDialog;
import com.johnrambo.ktea.common.klogutil.KLog;

import java.util.ArrayList;

public class RankAdapter3 extends BaseQuickAdapter<RankEntity, BaseViewHolderEx> {
    private Context mContext;
    private int type = 0;//0是正常模式展示 1代表第8个要展示更多
    private ArrayList<NavigationEntity> data;

    public RankAdapter3(int layoutResId, Context context, @io.reactivex.annotations.Nullable ArrayList<RankEntity> data,int type) {
        super(layoutResId, data);
        this.mContext = context;
        this.type = type;
    }

    @Override
    protected void convert(BaseViewHolderEx helper, RankEntity entity) {
        LinearLayout llBg = helper.getView(R.id.llBg);
        TextView tv1 = helper.getView(R.id.tv1);
        TextView tv2 = helper.getView(R.id.tv2);
        TextView tv3 = helper.getView(R.id.tv3);
        TextView tv32 = helper.getView(R.id.tv32);
        TextView tv4 = helper.getView(R.id.tv4);
        TextView tv5 = helper.getView(R.id.tv5);
        if(helper.getItemPosition()%2==0){
            llBg.setBackgroundColor(Color.parseColor("#ffffff"));
        }else{
            llBg.setBackgroundColor(Color.parseColor("#f7f7f7"));
        }
        if(type==1||type==0||type==5){
            LinearLayout.LayoutParams params= (LinearLayout.LayoutParams) tv2.getLayoutParams();
            params.width=0;
            params.weight=1;
            tv2.setLayoutParams(params);
        }
        if(type==5){
            tv3.setVisibility(View.VISIBLE);
            tv32.setVisibility(View.GONE);
        }else{
            if(type==2){
                tv3.setVisibility(View.GONE);
                tv32.setVisibility(View.VISIBLE);
                tv32.setText(entity.getPhone());
            }else{
                tv3.setVisibility(View.GONE);
                tv32.setVisibility(View.GONE);
            }
        }
        tv1.setText((helper.getItemPosition()+1)+"");
        tv2.setText(entity.getRegion()+entity.getCity());
//        5 全部 1 每天（粉丝） 2 每周（会员） 4 每月（粉丝+会员） 0 （游客）
        if("0".equals(entity.getUserType())){
            tv3.setText("游客");
        }else if("1".equals(entity.getUserType())){
            tv3.setText("粉丝");
        }else{
            tv3.setText("会员");
        }
        tv4.setText(entity.getVisitNum());
        tv5.setText(Utils.getAccurateDate(entity.getCreateTime()));
        helper.getItemView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new Rank2Dialog(mContext, type,entity).show();
            }
        });
    }
}